package Bean;

import java.security.NoSuchAlgorithmException;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Login extends Database {

	private CheckValue mCheck = new CheckValue();
	private String mUsername = "";
	private String mPassword = "";
	
	public void setUsername(String username) {
		mUsername = username;
	}
	
	public void setPassword(String password) {
		mPassword = password;
	}

	public int getLoginId() {
		String pw = "";

		try {
			pw = mCheck.getMD5(mPassword);
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String sql = "SELECT id FROM members WHERE username = '" + mUsername + "' and password = '" + pw + "'";

		try {
			ResultSet rs = mStmt.executeQuery(sql);
			
			if (rs.next()) {
				return rs.getInt("id");
			} else {
				return 0;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return 0;
	}
}
